<template>
  <div>
    <div class="title">
      <span><i>1</i>输入找回账号</span>
      <span class="active"><i>2</i>回答密保问题</span>
      <span><i>3</i>重置密码</span>
    </div>
    <div class="box">
      <div class="input-item">
        <label> 用户名：</label>
        <input type="text" value="xxxx" disabled v-model="username" />
      </div>
      <div class="input-item">
        <label> 手机号：</label>
        <input type="text" value="xxxx" disabled v-model="phone1" />
      </div>
      <div class="input-item">
        <label>密保问题：</label>
        <input type="text" value="xxxxxxx" disabled v-model="question" />
      </div>
      <div class="input-item">
        <label>密保答案：</label>
        <input type="text" v-model="answer" />
      </div>
      <button @click="prev('step1')">上一步</button>
      <button @click="end(answer, id, 'step3')">下一步</button>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  props: {
    phone: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      username: "",
      phone1: "",
      question: "",
      answer: "",
      id: "",
    };
  },
  // 发送请求
  async created() {
    const { data: res } = await axios.get(
      `http://124.223.14.236:3001/api/user/findPwd?phone=${this.phone}`
    );
    console.log(res);
    this.username = res.data.username;
    this.phone1 = res.data.phone;
    this.question = res.data.question;
    this.id = res.data.id;
  },
  methods: {
    // 上一步
    prev(value) {
      console.log(value);
      this.$emit("prev", value);
    },
    end(answer, id, value) {
      if (this.answer.length === 0) {
        return alert("请输入密保答案");
      }
      this.$emit("end", answer, id, value);
    },
  },
};
</script>

<style scoped>
@import url("@/assets/css/index.css");
</style>
